home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gscspace.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  7.9 KB  |  300 lines

  1. /* Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gscspace.c,v 1.4 2000/09/19 19:00:27 lpd Exp $ */
  20. /* Color space operators and support */
  21. #include "memory_.h"
  22. #include "gx.h"
  23. #include "gserrors.h"
  24. #include "gsstruct.h"
  25. #include "gsccolor.h"
  26. #include "gsutil.h"        /* for gs_next_ids */
  27. #include "gxcmap.h"
  28. #include "gxcspace.h"
  29. #include "gxistate.h"
  30.  
  31. /*
  32.  * Define the standard color space types.  We include DeviceCMYK in the base
  33.  * build because it's too awkward to omit it, but we don't provide any of
  34.  * the PostScript operator procedures (setcmykcolor, etc.) for dealing with
  35.  * it.
  36.  */
  37. private const gs_color_space_type gs_color_space_type_DeviceGray = {
  38.     gs_color_space_index_DeviceGray, true, true,
  39.     &st_base_color_space, gx_num_components_1,
  40.     gx_no_base_space, gx_cspace_is_equal,
  41.     gx_init_paint_1, gx_restrict01_paint_1,
  42.     gx_same_concrete_space,
  43.     gx_concretize_DeviceGray, gx_remap_concrete_DGray,
  44.     gx_remap_DeviceGray, gx_no_install_cspace,
  45.     gx_no_adjust_cspace_count, gx_no_adjust_color_count
  46. };
  47. private const gs_color_space_type gs_color_space_type_DeviceRGB = {
  48.     gs_color_space_index_DeviceRGB, true, true,
  49.     &st_base_color_space, gx_num_components_3,
  50.     gx_no_base_space, gx_cspace_is_equal,
  51.     gx_init_paint_3, gx_restrict01_paint_3,
  52.     gx_same_concrete_space,
  53.     gx_concretize_DeviceRGB, gx_remap_concrete_DRGB,
  54.     gx_remap_DeviceRGB, gx_no_install_cspace,
  55.     gx_no_adjust_cspace_count, gx_no_adjust_color_count
  56. };
  57. private const gs_color_space_type gs_color_space_type_DeviceCMYK = {
  58.     gs_color_space_index_DeviceCMYK, true, true,
  59.     &st_base_color_space, gx_num_components_4,
  60.     gx_no_base_space, gx_cspace_is_equal,
  61.     gx_init_paint_4, gx_restrict01_paint_4,
  62.     gx_same_concrete_space,
  63.     gx_concretize_DeviceCMYK, gx_remap_concrete_DCMYK,
  64.     gx_remap_DeviceCMYK, gx_no_install_cspace,
  65.     gx_no_adjust_cspace_count, gx_no_adjust_color_count
  66. };
  67.  
  68. /* Structure descriptors */
  69. public_st_color_space();
  70. public_st_base_color_space();
  71.  
  72. /* Return the shared instances of the color spaces. */
  73. const gs_color_space *
  74. gs_cspace_DeviceGray(const gs_imager_state * pis)
  75. {
  76.     return pis->shared->device_color_spaces.named.Gray;
  77. }
  78. const gs_color_space *
  79. gs_cspace_DeviceRGB(const gs_imager_state * pis)
  80. {
  81.     return pis->shared->device_color_spaces.named.RGB;
  82. }
  83. const gs_color_space *
  84. gs_cspace_DeviceCMYK(const gs_imager_state * pis)
  85. {
  86.     return pis->shared->device_color_spaces.named.CMYK;
  87. }
  88.  
  89. /* ------ Create/copy/destroy ------ */
  90.  
  91. void
  92. gs_cspace_init(gs_color_space *pcs, const gs_color_space_type * pcstype,
  93.            gs_memory_t *mem)
  94. {
  95.     pcs->type = pcstype;
  96.     pcs->pmem = mem;
  97.     pcs->id = gs_next_ids(1);
  98. }
  99.  
  100. int
  101. gs_cspace_alloc(gs_color_space ** ppcspace,
  102.         const gs_color_space_type * pcstype,
  103.         gs_memory_t * mem)
  104. {
  105.     gs_color_space *pcspace =
  106.     gs_alloc_struct(mem, gs_color_space, &st_color_space,
  107.             "gs_cspace_alloc");
  108.  
  109.     if (pcspace == 0)
  110.     return_error(gs_error_VMerror);
  111.     gs_cspace_init(pcspace, pcstype, mem);
  112.     *ppcspace = pcspace;
  113.     return 0;
  114. }
  115.  
  116. int
  117. gs_cspace_init_DeviceGray(gs_color_space *pcs)
  118. {
  119.     gs_cspace_init(pcs, &gs_color_space_type_DeviceGray, NULL);
  120.     return 0;
  121. }
  122. int
  123. gs_cspace_build_DeviceGray(gs_color_space ** ppcspace, gs_memory_t * pmem)
  124. {
  125.     return gs_cspace_alloc(ppcspace, &gs_color_space_type_DeviceGray, pmem);
  126. }
  127.  
  128. int
  129. gs_cspace_init_DeviceRGB(gs_color_space *pcs)
  130. {
  131.     gs_cspace_init(pcs, &gs_color_space_type_DeviceRGB, NULL);
  132.     return 0;
  133. }
  134. int
  135. gs_cspace_build_DeviceRGB(gs_color_space ** ppcspace, gs_memory_t * pmem)
  136. {
  137.     return gs_cspace_alloc(ppcspace, &gs_color_space_type_DeviceRGB, pmem);
  138. }
  139.  
  140. int
  141. gs_cspace_init_DeviceCMYK(gs_color_space *pcs)
  142. {
  143.     gs_cspace_init(pcs, &gs_color_space_type_DeviceCMYK, NULL);
  144.     return 0;
  145. }
  146. int
  147. gs_cspace_build_DeviceCMYK(gs_color_space ** ppcspace, gs_memory_t * pmem)
  148. {
  149.     return gs_cspace_alloc(ppcspace, &gs_color_space_type_DeviceCMYK, pmem);
  150. }
  151.  
  152. /*
  153.  * Copy just enough of a color space object.  This will do the right thing
  154.  * for copying color spaces into the base or alternate color space of a
  155.  * compound color space when legal, but it can't check that the operation is
  156.  * actually legal.
  157.  */
  158. inline private void
  159. cs_copy(gs_color_space *pcsto, const gs_color_space *pcsfrom)
  160. {
  161.     memcpy(pcsto, pcsfrom, pcsfrom->type->stype->ssize);
  162. }
  163.  
  164. /* Copy a color space into one newly allocated by the caller. */
  165. void
  166. gs_cspace_init_from(gs_color_space * pcsto, const gs_color_space * pcsfrom)
  167. {
  168.     cs_copy(pcsto, pcsfrom);
  169.     (*pcsto->type->adjust_cspace_count)(pcsto, 1);
  170. }
  171.  
  172. /* Assign a color space into a previously initialized one. */
  173. void
  174. gs_cspace_assign(gs_color_space * pdest, const gs_color_space * psrc)
  175. {
  176.     /* check for a = a */
  177.     if (pdest == psrc)
  178.     return;
  179.     (*psrc->type->adjust_cspace_count)(psrc, 1);
  180.     (*pdest->type->adjust_cspace_count)(pdest, -1);
  181.     cs_copy(pdest, psrc);
  182. }
  183.  
  184.  
  185. /* Prepare to free a color space. */
  186. void
  187. gs_cspace_release(gs_color_space * pcs)
  188. {
  189.     (*pcs->type->adjust_cspace_count)(pcs, -1);
  190. }
  191.  
  192. /* ------ Accessors ------ */
  193.  
  194. /* Get the index of a color space. */
  195. gs_color_space_index
  196. gs_color_space_get_index(const gs_color_space * pcs)
  197. {
  198.     return pcs->type->index;
  199. }
  200.  
  201. /* Get the number of components in a color space. */
  202. int
  203. gs_color_space_num_components(const gs_color_space * pcs)
  204. {
  205.     return cs_num_components(pcs);
  206. }
  207.  
  208. /* Restrict a color to its legal range. */
  209. void
  210. gs_color_space_restrict_color(gs_client_color *pcc, const gs_color_space *pcs)
  211. {
  212.     cs_restrict_color(pcc, pcs);
  213. }
  214.  
  215. /* Test whether two color spaces are equal. */
  216. bool
  217. gs_color_space_equal(const gs_color_space *pcs1, const gs_color_space *pcs2)
  218. {
  219.     return ((pcs1->id == pcs2->id && pcs1->id != gs_no_id) ||
  220.         (pcs1->type == pcs1->type && pcs1->type->equal(pcs1, pcs2)));
  221. }
  222.  
  223. int
  224. gx_num_components_1(const gs_color_space * pcs)
  225. {
  226.     return 1;
  227. }
  228. int
  229. gx_num_components_3(const gs_color_space * pcs)
  230. {
  231.     return 3;
  232. }
  233. int
  234. gx_num_components_4(const gs_color_space * pcs)
  235. {
  236.     return 4;
  237. }
  238.  
  239. /*
  240.  * For color spaces that have a base or alternative color space, return that
  241.  * color space. Otherwise return null.
  242.  */
  243. const gs_color_space *
  244. gs_cspace_base_space(const gs_color_space * pcspace)
  245. {
  246.     return cs_base_space(pcspace);
  247. }
  248.  
  249. const gs_color_space *
  250. gx_no_base_space(const gs_color_space * pcspace)
  251. {
  252.     return NULL;
  253. }
  254.  
  255. /* ------ Other implementation procedures ------ */
  256.  
  257. /* Color space equality procedure for color spaces with no parameters. */
  258. bool
  259. gx_cspace_is_equal(const gs_color_space *pcs1, const gs_color_space *pcs2)
  260. {
  261.     return true;
  262. }
  263.  
  264. /* Color space equality procedure for cases where a real test is too hard. */
  265. bool
  266. gx_cspace_not_equal(const gs_color_space *pcs1, const gs_color_space *pcs2)
  267. {
  268.     return false;
  269. }
  270.  
  271. /* Null color space installation procedure. */
  272. int
  273. gx_no_install_cspace(const gs_color_space * pcs, gs_state * pgs)
  274. {
  275.     return 0;
  276. }
  277.  
  278. /* Null reference count adjustment procedure. */
  279. void
  280. gx_no_adjust_cspace_count(const gs_color_space * pcs, int delta)
  281. {
  282. }
  283.  
  284. /* GC procedures */
  285.  
  286. private 
  287. ENUM_PTRS_BEGIN_PROC(color_space_enum_ptrs)
  288. {
  289.     EV_CONST gs_color_space *pcs = vptr;
  290.  
  291.     return ENUM_USING(*pcs->type->stype, vptr, size, index);
  292.     ENUM_PTRS_END_PROC
  293. }
  294. private 
  295. RELOC_PTRS_WITH(color_space_reloc_ptrs, gs_color_space *pcs)
  296. {
  297.     RELOC_USING(*pcs->type->stype, vptr, size);
  298. }
  299. RELOC_PTRS_END
  300.